package cn.com.yusys.yusp.admin.web.rest;

import cn.com.yusys.yusp.admin.domain.AdminSmLookup;
import cn.com.yusys.yusp.admin.service.AdminSmLookupService;
import cn.com.yusys.yusp.commons.exception.MessageConstants;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @项目名称: yusp-admin
 * @类名称: AdminSmLookupResource
 * @类描述: 数据字典类别
 * @功能描述: 
 * @创建人: liaoxd@yusys.com.cn
 * @创建时间: 2017-12-27 17:49
 * @修改备注: 
 * @修改记录: 修改时间    修改人员    修改原因
 * -------------------------------------------------------------
 * @version 1.0.0
 * @Copyright (c) 2017宇信科技-版权所有
 */
@RestController
@RequestMapping("/api/adminsmLookup")
public class AdminSmLookupResource extends CommonResource<AdminSmLookup, String> {

	@Autowired
	private AdminSmLookupService adminSmLookupService;

	private final Logger log = LoggerFactory.getLogger(AdminSmLookupResource.class);

	@Override
	protected CommonService getCommonService() {
		return this.adminSmLookupService;
	}


	/**
	* @方法名称: deleteMult
	* @方法描述: 多个删除
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@PostMapping("/deletes/{ids}")
	public ResultDto<Integer> deleteMult(
			@ApiParam(value = "Object Of PK id", required = true) @PathVariable String ids) {
		log.debug("REST request to delete Object : {}", ids);
		String[] id = ids.toString().split(",");
		int i;
		for (i = 0; i < id.length; i++) {
			this.adminSmLookupService.deleteByLookupCode(id[i]);
		}
		int result = i;
		ResultDto<Integer> resultDto = new ResultDto<Integer>();
		if(result >= 1){
			resultDto.setMessage("删除成功!");
		}
		resultDto.setData(result);
		return resultDto;

	}

	/**
	* @方法名称: updateSelective
	* @方法描述: 修改接口
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@PostMapping("/updates")
	public ResultDto<Integer> updateSelective(@ApiParam(value = "Object", required = true) @RequestBody AdminSmLookup t)
			throws URISyntaxException {
		log.debug("REST request to update Object : {}", t);

		int result = getCommonService().updateSelective(t);
		ResultDto<Integer>	resultDto = new ResultDto<>();
		if(result >=1 ){
			resultDto.setMessage("修改成功！");
		}
		resultDto.setData(result);
		return resultDto;
	}

	
	
	/**
     * @函数名称:createValidate
     * @函数描述:实体类创建，加重复性校验
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/createvalidate")
    protected ResultDto<AdminSmLookup> createValidate(@ApiParam(value = "Object", required = true) @RequestBody AdminSmLookup t)
            throws URISyntaxException {
        log.debug("REST request to save Object : {}", t);
        int result = this.adminSmLookupService.insert(t);
        ResultDto<AdminSmLookup> resultDto = new ResultDto<AdminSmLookup>(t);
        if(result == 0) {
        	resultDto.setCode(MessageConstants.RET_CODE_20100002);
        	resultDto.setMessage("类别代码已存在,请勿重复!");
        } else {
        	List<Object> i18nData = new ArrayList<Object>();
        	i18nData.add(t.getLookupCode());
        	resultDto.setCode(MessageConstants.RET_CODE_20100003);
        	resultDto.setI18nData(i18nData);
        	resultDto.setMessage("新增类别代码"+t.getLookupCode()+"成功！");
		}

       return resultDto;
    }

	

}
